<?php if (!$sf_request->isMethod('POST')): ?>
    <?php echo '<div id="refer-friend-form-holder">' ?>
<?php endif; ?>
<?php include_partial('common/flashes') ?>
<form id="refer-friend-form" action="<?php echo url_for('@refer_friend') ?>" method="post">
    <div class="imperative">Kindly send your friends an invite to join DocPlus</div>
    <?php echo $form->renderHiddenFields(true) ?>
    <?php for ($i = -1; $i < $friends; $i++): ?>
        <?php if ($i == -1): ?>
            <div class="friend">
                <div class="friend-name-fields">
                    <?php include_partial("common/input_field", array("form" => $form, "field" => "from_name")) ?>
                </div>    
                <div class="friend-email-fields">
                    <?php include_partial("common/input_field", array("form" => $form, "field" => "from_email")) ?>
                </div>
            </div>
        <?php else: ?>
            <div class="friend">
                <div class="friend-name-fields">
                    <?php include_partial("common/input_field", array("form" => $form[$i], "field" => "name", "name_format" => $form->getName() . "_" . $i)) ?>
                </div>
                <div class="friend-email-fields">
                    <?php include_partial("common/input_field", array("form" => $form[$i], "field" => "email", "name_format" => $form->getName() . "_" . $i)) ?>
                </div>
            </div>
        <?php endif; ?>
    <?php endfor; ?>
    <div class="friend">
        <div class="friend-message">
            <?php include_partial("common/input_field", array("form" => $form, "field" => "message")) ?>
        </div>
    </div>
    <div class="row">
        <ul>
            <li>
                <button id="submit-refer-friend" type="submit" class="blue-button-30">Submit</button>
                <input id="done-refer-friend" type="button" value="Done" class="brown-button-30">
            </li>
        </ul>
    </div>
    <div class="clear"></div>
</form>
<script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){
        // make an attempt to submit this form
        $('#submit-refer-friend').click(function() {
            $('#refer-friend-form').ajaxSubmit(function(data){                 
                $("#refer-friend-form-holder").html(data);
            });
            return false;
        });
        
        $("#done-refer-friend").click(function(){            
            $.fn.colorbox.close();
        }); 
    });
    //]]>
</script>
<?php if (!$sf_request->isMethod('POST')): ?>
    <?php echo '</div>' ?>
<?php endif; ?>